/****private function***/

function __init(){
	$addEvent($('userList') , "click" , setActionWindow);
}

function modFn(el){
	var text = http_request.responseText;
	if(text.indexOf('fail')!=-1){
		alert("Update Failed!");
		var tr = el.parentNode.parentNode;
		var tds = tr.getElementsByTagName("td");
		var inps = tr.getElementsByTagName("input");
		inps[0].className = "hideInput";
		inps[0].readOnly =  true;
		inps[1].style.display = "";
		inps[2].style.display = "none";
	}
	else{
		alert("Update Succeed!");
	}
}

function setActionWindow(e){
	var el = getSrcEl(e);
	if(el.tagName=="INPUT"){
		var action=el.getAttribute("tag");
		var userid = el.getAttribute("userid");
		if(action=="add"){
			showAddWindow();
		}
		if(action=="modify"){
			makeModifyUser(el);
		}
		if(action=="saveModify"){
			ajaxModifyUser(el , userid);
		}
		if(action=="delete"){
			ajaxDeleteUser(userid);
		}
	}
}


function makeModifyUser(el){
	var tr = el.parentNode.parentNode;
	var tds = tr.getElementsByTagName("td");
	var inps = tr.getElementsByTagName("input");
	inps[0].className = "showInput";
	inps[0].readOnly = false;
	inps[1].style.display = "none";
	inps[2].style.display = "";
}

function ajaxModifyUser(el , uid){
	var tr = el.parentNode.parentNode;
	var tds = tr.getElementsByTagName("td");
	var inps = tr.getElementsByTagName("input");
	var value = inps[0].value.trim();

	if(!/[0-9]+/.test(value)||value==""){
		alert("please fill the value and the value must be integer.");
		return;
	}

	inps[0].className = "hideInput";
	inps[0].readOnly = true;
	inps[1].style.display = "";
	inps[2].style.display = "none";
	
	var action = "action=modconfig";
	var userid = "&cid="+encodeURI(uid);
	var value = "&value="+encodeURI(value);
	var param = action+userid+value;
	makeAjaxRequest(ajaxUrl , param , true , modFn.pass(el));
}

__domready();